package com.team.ai.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.stp.StpUtil;
import com.team.ai.entity.ResultEntity;
import com.team.ai.service.CollectionService;
import jakarta.annotation.Resource;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@CrossOrigin//跨域
@RestController//遵循RestFul
@RequestMapping("v2/collection/")
public class CollerctionController {
    @Resource
    private RedisTemplate<String, String> redisTemplate;//Redis工具类
    @Resource
    CollectionService collectionService;
    @SaCheckLogin
    @PostMapping("insert")
    public String insert(
            @RequestParam(value = "vbId",defaultValue = "-1") int vbId,
            @RequestParam(value = "idx",defaultValue = "-1") int idx
    ){
        int userId = StpUtil.getLoginIdAsInt();
        return collectionService.insert(userId,vbId,idx);
    }
    @SaCheckLogin
    @DeleteMapping("delete")
    public String delete(
            @RequestParam(value = "vbId",defaultValue = "-1") int vbId,
            @RequestParam(value = "idx",defaultValue = "-1") int idx
    ){
        int userId = StpUtil.getLoginIdAsInt();
        return collectionService.delete(userId,vbId,idx);
    }
    @SaCheckLogin
    @GetMapping("selectList")
    public String selectList(@RequestParam(value = "idx",defaultValue = "-1") int idx){
        int userId = StpUtil.getLoginIdAsInt();
        return collectionService.selectList(userId,idx);
    }

}
